Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add noise hits to reconstructed hits by randomly generating cell id #1643

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

ShujieL
Copy link
Contributor

@ShujieL ShujieL commented Oct 25, 2024

Briefly, what does this PR introduce?

add noise hits to reconstructed hits by randomly generating cell id.
for test only. The generated cell ID is not always on sensitive surface.

What kind of change does this PR introduce?

  • Bug fix (issue #__)
  • [x ] New feature (issue #__)
  • Documentation update
  • Other: __

Please check if this PR fulfills the following:

  • Tests for the changes have been added
  • Documentation has been added / updated
  • [x ] Changes have been communicated to collaborators

Does this PR introduce breaking changes? What changes might users need to make to their code?

Does this PR change default behavior?

@ShujieL ShujieL marked this pull request as draft October 25, 2024 18:41
@github-actions github-actions bot added the topic: tracking Relates to tracking reconstruction label Oct 25, 2024
Comment on lines +110 to +112
std::random_device rd; // Obtain a random number from hardware
std::mt19937_64 eng(rd()); // Seed the generator
std::uniform_int_distribution<uint64_t> distr; // Define the range for 64-bit integers
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do not create a new random device for every hit.

Comment on lines +146 to +148
#if EDM4EIC_VERSION_MAJOR >= 7
auto rec_hit =
#endif
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
#if EDM4EIC_VERSION_MAJOR >= 7
auto rec_hit =
#endif

Not needed if you don't need to set a relation.

Comment on lines +92 to +96
//------------------------------------------------
// Example code of adding random noise hits
// Shujie Li, 08.2024
// use the first raw hits to obtain the volume ID of the detector system
// this also make sure the hit container has at least one hit
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
//------------------------------------------------
// Example code of adding random noise hits
// Shujie Li, 08.2024
// use the first raw hits to obtain the volume ID of the detector system
// this also make sure the hit container has at least one hit
// Use the first raw hits to obtain the volume ID of the detector system.
// This also make sure the hit container has at least one hit.

And add your name on the second line of the file.

std::random_device rd; // Obtain a random number from hardware
std::mt19937_64 eng(rd()); // Seed the generator
std::uniform_int_distribution<uint64_t> distr; // Define the range for 64-bit integers
dd4hep::Position pos;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
dd4hep::Position pos;

uint64_t randomNum = distr(eng); // Generate a random 64-bit number
randomNum = (randomNum & ~uint64_t(0xFF)) | vol_id; // Clear the last 8 bits and set them to 'vol ID'
try {
pos = m_converter->position(randomNum);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
pos = m_converter->position(randomNum);
auto pos = m_converter->position(randomNum);

// std::cout<<"::: cell ID error caught"<<std::endl;
nn++;
}
std::cout <<std::bitset<8>(vol_id) <<":"<< i<<"/"<<nn<<":::"<<randomNum<<" ";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please, remove "cout" output (even commented), or replace with clearly worded debug logging.

Comment on lines +114 to +115
int nn=0;
int i=0;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please give clear name to the variables.

Suggested change
int nn=0;
int i=0;
unsigned int num_failures = 0;
unsigned int num_generated_hits = 0;

Comment on lines +102 to +106
uint64_t id0,vol_id;
id0 = hit0.getCellID();
// vol ID is the last 8 bits in Si tracker. Need to make it more flexible
// may want to predefine the layer/module ID as well to speed up the radom ID generation
vol_id = id0 & 0xFF;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we not call it "system ID"?

Suggested change
uint64_t id0,vol_id;
id0 = hit0.getCellID();
// vol ID is the last 8 bits in Si tracker. Need to make it more flexible
// may want to predefine the layer/module ID as well to speed up the radom ID generation
vol_id = id0 & 0xFF;
uint64_t id0, system_id;
id0 = hit0.getCellID();
// system ID is the last 8 bits in Si tracker. Need to make it more flexible
// may want to predefine the layer/module ID as well to speed up the radom ID generation
system_id = id0 & 0xFF;

Comment on lines +117 to +118
uint64_t randomNum = distr(eng); // Generate a random 64-bit number
randomNum = (randomNum & ~uint64_t(0xFF)) | vol_id; // Clear the last 8 bits and set them to 'vol ID'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like how this is clear and simple, but is performance terrible or not?

Comment on lines +95 to +96
// use the first raw hits to obtain the volume ID of the detector system
// this also make sure the hit container has at least one hit
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this something that you really want or just a consequence of how you're getting the volume? Might it not be better to have a completely separate algorithm which constructs these hits from knowledge of the readout structure to get the volume rather than relying on their being a hit.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topic: tracking Relates to tracking reconstruction
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants